#!/bin/bash

#Sample script that run a program, compare its 
#stdout to an existing correct output file, and shows
#the execution time of the program. That is repeated N times.

#You can use this script to create another one that
#can be parametrized with the name of the program that you
#want to execute, with the parameters that you want to pass
#to this program, that save the output results to a file
#that can be imported by Openoffice, etc.

#Parameters

N=5			# Number of times you want to execute the program
PROG=echo		# Program name
PARS='a b c'		# Program parameters

out=/tmp/out.$$		# Temporal file where you save the execution results

i=1
while (test $i -lt $N)
do
	echo Run $i:
	/usr/bin/time $PROG $PARS > $out
	if (test -f "out.$PROG.$PARS")
	then
		if (cmp "out.$PROG.$PARS" $out)
		then
			echo Correct Execution
			echo
		else
			echo Wrong Execution
			echo Compare out.$PROG.$PARS to $out
			exit
		fi
	else
		echo There is not output file out.$PROG.$PARS to compare to
	fi
	rm -f $out
	i=`expr $i + 1`
done

